package homework;

import java.util.ArrayList;
import java.util.List;

public class SortPoint {
    public static void main(String[] args) {
        List<Point> list=new ArrayList<>();
        list.add(new Point(3,5));
        list.add(new Point(5,8));
        list.add(new Point(2,5));
        list.add(new Point(9,7));
        list.add(new Point(8,6));
        list.add(new Point(9,1));
        System.out.println(list);

        list.sort((o1, o2) -> {
            int a=o1.getX()*o1.getX()+o1.getY()*o1.getY();
            int b=o2.getX()*o2.getX()+o2.getY()*o2.getY();
            return a-b;
        });
        System.out.println(list);

        list.sort((o1, o2) -> {
            if(o1.getX()==o2.getX()){
                return o1.getY()-o2.getY();
            }else{
                return o1.getX()-o2.getX();
            }
        });
        System.out.println(list);
    }
}
